package communicationsPORTS;

import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;

import java.util.Enumeration;
import java.util.HashMap;

public class Ports {

	@SuppressWarnings("unchecked")
	Enumeration pList;
	@SuppressWarnings("unchecked")
	HashMap porty = new HashMap();
	
 @SuppressWarnings("unchecked")
 public Ports() {
	 
	 pList = CommPortIdentifier.getPortIdentifiers();
	 
	 int i = 0;
	 
	 while (pList.hasMoreElements()) {
		      CommPortIdentifier cpi = (CommPortIdentifier)pList.nextElement();
		      porty.put(i,cpi);
		      i++;
		  }
 }
 
 public CommPortIdentifier getPortId(String PortName) throws NoSuchPortException{
	 
	 CommPortIdentifier PortIdTemp = null;
	 int i = 0; 
	 
	 while (porty.size()>i) {
	      
	      if (((CommPortIdentifier) porty.get(i)).getName().equals(PortName)) {
	    	  PortIdTemp = (CommPortIdentifier) porty.get(i); 
	      }
	      i++;
	    }
	 return PortIdTemp;	
 }
 
 @SuppressWarnings("unchecked")
public HashMap getPortMap (){
	 return porty;
 }
 
 @SuppressWarnings("unchecked")
public Enumeration getEList(){
	 return pList;
 }
 
}
